Telegram Group & Telegram Channel
💭 Что такое интроспекция в Python?

Интроспекция — это способность программы изучать объекты во время выполнения: узнавать их тип, структуру, атрибуты, методы и даже иерархию наследования.

🧩 Это мощный инструмент, встроенный в Python (а также доступный в других языках, например Java, PHP, Ruby). Он позволяет, например:

— Проверить тип объекта с помощью type()
— Проверить, к какому классу принадлежит объект — isinstance(obj, Class)
— Получить список доступных атрибутов и методов — dir(obj)
— Изучить содержимое объекта — через __dict__

Пример:
class Foo:
def __init__(self, val):
self.x = val
def bar(self):
return self.x

obj = Foo(5)
print(dir(obj))


Результат:
['__class__', '__dict__', ..., 'bar', 'x']


Это удобно для отладки, разработки, рефлексии, создания универсальных функций, которые могут работать с разными типами данных.

Библиотека собеса по Python
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/py_interview_lib/805
Create:
Last Update:

💭 Что такое интроспекция в Python?

Интроспекция — это способность программы изучать объекты во время выполнения: узнавать их тип, структуру, атрибуты, методы и даже иерархию наследования.

🧩 Это мощный инструмент, встроенный в Python (а также доступный в других языках, например Java, PHP, Ruby). Он позволяет, например:

— Проверить тип объекта с помощью type()
— Проверить, к какому классу принадлежит объект — isinstance(obj, Class)
— Получить список доступных атрибутов и методов — dir(obj)
— Изучить содержимое объекта — через __dict__

Пример:

class Foo:
def __init__(self, val):
self.x = val
def bar(self):
return self.x

obj = Foo(5)
print(dir(obj))


Результат:
['__class__', '__dict__', ..., 'bar', 'x']


Это удобно для отладки, разработки, рефлексии, создания универсальных функций, которые могут работать с разными типами данных.

Библиотека собеса по Python

BY Библиотека собеса по Python | вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/py_interview_lib/805

View MORE
Open in Telegram


Библиотека собеса по Python | вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

Telegram announces Search Filters

With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.

The SSE was the first modern stock exchange to open in China, with trading commencing in 1990. It has now grown to become the largest stock exchange in Asia and the third-largest in the world by market capitalization, which stood at RMB 50.6 trillion (US$7.8 trillion) as of September 2021. Stocks (both A-shares and B-shares), bonds, funds, and derivatives are traded on the exchange. The SEE has two trading boards, the Main Board and the Science and Technology Innovation Board, the latter more commonly known as the STAR Market. The Main Board mainly hosts large, well-established Chinese companies and lists both A-shares and B-shares.

Библиотека собеса по Python | вопросы с собеседований from es


Telegram Библиотека собеса по Python | вопросы с собеседований
FROM USA